/***************************************************************************
 *   Copyright (C) 2008 by Ivan Blagoev Topolsky   *
 *   ivan.topolsky@genebio.com   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU Library General Public License as       *
 *   published by the Free Software Foundation; either version 3 of the    *
 *   License, or (at your option) any later version.                       *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU Library General Public     *
 *   License along with this program; if not, write to the                 *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#ifndef BOL_XENO_MERLINFILTERPARSE_H
#define BOL_XENO_MERLINFILTERPARSE_H

#include <string>

#include <boost/regex.hpp>
#include <boost/lexical_cast.hpp>

namespace xeno {

namespace merlin {
	using namespace std;
	using namespace boost;
	using namespace boost::regex_constants;
	
/**
	this class is as helper to parse Xcalibur's XFilter text string
	as after 1 month I still haven't had any contact with Thermo
	the content of this filter is heavily based on the "FilterLine"
	class used by Sashimi projet.

	NOTE as we use more heavily STL & BOOST templates and are less dependant on Win32 API, our task is a little bit easier

	TODO try to finally get Thermo and get official documentation

	@author Ivan Blagoev Topolsky <ivan.topolsky@genebio.com>
*/
class FilterParse : public map<string, string> {
	const string txt;
	smatch rmatch;
	
public:
	FilterParse(const string& newtxt );

	~FilterParse() {
	}
	
	const string& Text() const { return txt; }
	int MSLevel() const;
	double SourceCID() const;
	double Energy() const;
	double Parent() const;

	// automatically create methods
#define STRING_METHODS \
	f_(Instrument);	\
	f_(Polarity);	\
	f_(ScanData);	\
	f_(IonizationMode);	\
	f_(Corona);	\
	f_(PhotoIoniziation);	\
	f_(DetectorSet);	\
	f_(Turboscan);	\
	f_(Enhanced);	\
	f_(Dependent);	\
	f_(Wideband);	\
	f_(AccuateMass);	\
	f_(Ultra);	\
	f_(ScanType);	\
	f_(Activation);

#define f_(NAME)  string NAME ()  const;
	STRING_METHODS
#undef f_

#ifdef KEEP_LISTS
#else
#undef STRING_METHODS
#endif
	


	double operator() (const string& key);
friend ostream& operator<< (ostream& o, FilterParse &p);
};


}
}

#endif

/**
Here's the documentation that the people from Sashimi have managed to obtain from thermo :


FilterLine dictionary
	--From Thermo


Analyzer:
	ITMS		Ion Trap
	TQMS		Triple Quad
	SQMS		Single Quad
	TOFMS		TOF
	FTMS		ICR
	Sector		Sector

Segment Scan Event   (Sectors only)

Polarity
-		Negative
+		Positive


Scan Data
c		centroid
p		profile


Ionization Mode
EI		Electron Impact
CI		Chemical Ionization
FAB		Fast Atom Bombardment
ESI		Electrospray
APCI		Atmospheric Pressure Chemical Ionization
NSI		Nanospray
TSP		Thermospray
FD		Field Desorption
MALDI	Matrix Assisted Laser Desorption Ionization
GD		Glow Discharge

Corona
corona			corona on
!corona		corona off

PhotoIoniziation
pi			photo ionization on
!pi			photo ionization off

Source CID
sid			source cid on			
!sid			source cid off


Detector set
det			detector set
!det			detector not set


TurboScan
t			turbo scan on
!t			turob scan off

Enhanced			(Sectors only)
E			enhanced on
!E			enhanced off

Dependent Type
d			data dependent active
!d			data dependent not-active

Wideband
w			wideband activation on
!w			wideband activation off

Accurate Mass
!AM			accurate mass not active
AM			accurate mass active 
AMI			accurate mass with internal calibration
AME			accurate mass with external calibration

Ultra
u			ultra on
!u			ultra off

Scan Type:
full			full scan
SIM			single ion monitor
SRM			single reaction monitor
CRM
z			zoom scan
Q1MS			q1 mass spec scan
Q3MS			q3 mass spec scan 

Sector Scan			(Sectors only)
BSCAN		b scan
ESCAN		e scan



MSorder

MS2			MSn order
MS3
…
MS15

Activation Type
cid			collision induced dissociation
mpd
ecd			electron capture dissociation
pqd			pulsed q dissociation
etd			electron transfer dissociation
hcd			high energy collision dissociation
sa			supplemental cid
ptr			proton transfer reaction

Free Region			(Sectors only)
ffr1			field free region 1
ffr2			field free region 2

Mass range
[low mass – high mass]
*/
